//
//  MSProjectDetailViewController.m
//  SocietySale
//
//  Created by Mike on 16/11/8.
//  Copyright © 2016年 Mike. All rights reserved.
//

#define BtnWidth           (SCREEN_WIDTH/2)

#import "MSProjectDetailViewController.h"
#import "MSDetailSituationTableVC.h"
#import "MSDetailContactsTableVC.h"
#import "MSDetailTradeTableVC.h"
#import "MSDetailFootprintTableVC.h"
#import "MSReleaseFooterViewController.h"
#import "MSMytradeViewController.h"
#import "MSCustomerRecommenVC.h"
#import "MSContactsCorrectViewController.h"
#import "MSMyFootprintViewController.h"
#import "MSRecommenDetailVC.h"
#import "MSSaleContactsOfPeopleVC.h"

@interface MSProjectDetailViewController ()
{
    NSString *currentTypeStr;
    NSString *currentStateStr;
}
@property (nonatomic, strong) MSProjectModel *projectModel;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *tradeHeaderView;
@property (nonatomic, strong) UIView *footerHeaderView;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, assign) float positionY;
//侧边view
@property (nonatomic, strong) UIImageView *sideView;
//选择条
@property (nonatomic, strong) HDMenuView          *menu;
@property (nonatomic, strong) HDImageMenuView     *imageMenu;
@property (nonatomic, strong) UIView              *headView;
@property (nonatomic, strong) UIView              *headBottomView;
//@property (nonatomic, strong) HDImageMenuView     *imageMenu;
@property (nonatomic, strong) GXButton            *tradeBtn;
@property (nonatomic, strong) GXButton            *releaseBtn;
@property (nonatomic, strong) GXButton            *footerBtn;
@property (nonatomic, strong) GXButton            *releaseFooterBtn;
@property (nonatomic, strong) MSDetailSituationTableVC         *situationList;
@property (nonatomic, strong) MSDetailContactsTableVC          *contactsList;
@property (nonatomic, strong) MSDetailTradeTableVC             *tradeList;
@property (nonatomic, strong) MSDetailFootprintTableVC         *footprintList;
@property (nonatomic, copy)   NSMutableAttributedString        *footerAttstr;
@property (nonatomic, copy)   NSMutableAttributedString        *tradeAttstr;
//当前列表
@property(nonatomic,strong)UIViewController *currentVC;
//列表数组
@property(nonatomic,retain)NSArray *shopListVCArray;
//列表加载标志
@property(nonatomic,retain)NSMutableArray *listLoadFlags;

@property (nonatomic, strong) MSSaleFilterViewController        *typeFilterVC;       //类型筛选
@property (nonatomic, strong) MSSaleFilterViewController        *stateFilterVC;      //状态筛选
@property (nonatomic, strong) MSSaleFilterViewController        *filterVC;           //筛选控件
@property (nonatomic, strong) NSMutableArray                    *filterVCArray;
@property (nonatomic, strong) NSMutableArray                    *stateVCArray;
@property (nonatomic, assign) NSInteger lastIndex;
@property (nonatomic, assign) NSInteger footerIndex;
@end

@implementation MSProjectDetailViewController

- (void)dealloc{
    for(UIView* view in [self.contentView subviews])
    {
        [view removeFromSuperview];
    }
    
    self.contentView=nil;
    self.VctrID=nil;
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [self.tradeList.tableView removeObserver:self forKeyPath:@"contentOffset"];
}

- (void)initNavigationBar{
    [super initNavigationBar];
    titleLable.text = @"项目详情";
    leftBarBtn.hidden = NO;
    rightBarBtn.hidden = NO;
    
    [rightBarBtn setImage:[UIImage imageNamed:@"more"] forState:UIControlStateNormal];
    [rightBarBtn addTarget:self action:@selector(rightBarBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self layOutSideView];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if ([self.filterVC.view superview]) {
        [self.filterVC dismiss];
    }
    if (_lastIndex != -1) {
        [self.imageMenu setBtnStateWithIndex:_lastIndex state:NO];
    }
    _sideView.hidden = YES;
    rightBarBtn.selected = NO;
}

- (void)initUI{
    self.menu = [[HDMenuView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40) titleArray:@[@"概况",@"联系人",@"交易",@"足迹"]];
    self.menu.font = [UIFont fontWithName:@"STHeitiSC-Light" size:15];
    self.menu.normalColor = [UIColor blackColor];
    self.menu.bottomLineColor = kBlueColor;
    self.menu.delegate = (id)self;
    self.menu.isHiddenGrayLine = NO;
    [self.contentView addSubview:self.menu];
    
    float height = self.contentView.height;

    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH, height-40)];
    _scrollView.contentSize = CGSizeMake(4*SCREEN_WIDTH, height-40);
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.bounces = NO;
    _scrollView.pagingEnabled = YES;
    _scrollView.delegate = (id)self;
    _scrollView.scrollsToTop = NO;
    [self.contentView addSubview:_scrollView];

    self.situationList = (MSDetailSituationTableVC*)[self creatTableListWithClassName:@"MSDetailSituationTableVC" frame:CGRectMake(0, 0, SCREEN_WIDTH, height-40)];
    self.situationList.enableRefresh = NO;
    self.situationList.enableRequest = NO;
    
    self.contactsList = (MSDetailContactsTableVC*)[self creatTableListWithClassName:@"MSDetailContactsTableVC" frame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, height-40)];
    self.contactsList.enableRefresh = NO;
    self.contactsList.enableRequest = NO;
    
    self.tradeList = (MSDetailTradeTableVC*)[self creatTableListWithClassName:@"MSDetailTradeTableVC" frame:CGRectMake(SCREEN_WIDTH*2, 0, SCREEN_WIDTH, height-40)];
    self.footprintList = (MSDetailFootprintTableVC*)[self creatTableListWithClassName:@"MSDetailFootprintTableVC" frame:CGRectMake(SCREEN_WIDTH*3, 0, SCREEN_WIDTH, height-40)];
    
    self.tradeList.tableView.scrollsToTop = NO;
    [self.tradeList.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];

    self.currentVC = self.situationList;
    
    self.shopListVCArray = @[self.situationList,self.contactsList,self.tradeList,self.footprintList];
    
    [self layoutHeadView];
    
//    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick)];
//    [self.contentView addGestureRecognizer:tapGesture];
    
    _lastIndex = -1;
    self.stateFilterVC = [self creatFilterVC];
    self.typeFilterVC = [self creatFilterVC];
    self.filterVCArray = [NSMutableArray arrayWithObjects:self.typeFilterVC,self.stateFilterVC, nil];
    [self fillFilterData];
//    self.typeFilterVC.dataArray = [@[@"全部",@"出售",@"求购"] mutableCopy];
//    self.stateFilterVC.dataArray = [@[@"全部",@"正在交易", @"公开显示", @"过期交易"] mutableCopy];
//    self.typeFilterVC.stateArray = [self creatStateArrayWithArray:self.typeFilterVC.dataArray];
//    self.stateFilterVC.stateArray = [self creatStateArrayWithArray:self.stateFilterVC.dataArray];
//    
//    self.stateVCArray = [NSMutableArray arrayWithObjects:self.typeFilterVC.stateArray,self.stateFilterVC.stateArray, nil];
    
    currentStateStr = @"";
    currentTypeStr = @"";
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.menu.selectedIndex = scrollView.contentOffset.x/SCREEN_WIDTH;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    _positionY = MAX(80, 158-self.tradeList.tableView.contentOffset.y);
}

- (void)layOutSideView{
    if (!_sideView) {
        _sideView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-85, 70, 80, 88)];
        UIImage *newImage = [[UIImage imageNamed:@"pop_bg"] stretchableImageWithLeftCapWidth:0 topCapHeight:35];
        _sideView.image = newImage;
        _sideView.userInteractionEnabled = YES;
        _sideView.clipsToBounds = YES;
        [self.view addSubview:_sideView];
        NSArray *titleArray = @[@"跟踪",@"关注"];
        for (int i =0; i<2; i++) {
            GXButton *sideButton = [GXButton buttonWithType:UIButtonTypeCustom];
            [sideButton setFrame:CGRectMake(0, 6+i*40, 80, 40)];
            sideButton.tag = 10+i;
            //                [sideButton setImage:[UIImage imageNamed:titleArray[i]] forState:UIControlStateNormal];
            sideButton.titleLabel.font = HeitiFont(15);
            [sideButton setTitle:titleArray[i] forState:UIControlStateNormal];
            [sideButton setTitleColor:kLightGrayColor forState:UIControlStateHighlighted];
            [sideButton addTarget:self action:@selector(sideButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [_sideView addSubview:sideButton];
            
            //                UIView *sublineView = [[UIView alloc] initWithFrame:CGRectMake(0, (i+1)*44, 45, 0.8)];
            //                sublineView.backgroundColor = kLightBlackColor;
            //                [_sideView addSubview:sublineView];
        }
        _sideView.hidden = YES;
    }
}

- (void)rightBarBtnAction:(GXButton*)btn{
    btn.selected = !btn.selected;
    if (btn.selected) {
        _sideView.hidden = NO;
    }
    else{
        _sideView.hidden = YES;
    }
}

- (void)sideButtonAction:(GXButton*)btn{
    if (btn.tag == 10) {
        [netEngine requestTrackProjectWithTarget:self.VctrID hudView:self.contentView projectId:_projectId];
    }
    else if (btn.tag == 11) {
        [netEngine requestAttentionProjectWithTarget:self.VctrID hudView:self.contentView projectId:_projectId];
    }
    _sideView.hidden = YES;
    rightBarBtn.selected = NO;
}

- (MSBaseTableViewController*)creatTableListWithClassName:(NSString*)className frame:(CGRect)frame{
    MSBaseTableViewController *tableVC = [[NSClassFromString(className) alloc] initWithStyle:UITableViewStylePlain];
    tableVC.view.frame = frame;
    tableVC.enableRefresh = YES;
    tableVC.enableRequest = YES;
    tableVC.delegate = (id)self;
    tableVC.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.scrollView addSubview:tableVC.view];

    return tableVC;
}

- (void)layoutHeadView{
    _tradeHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 118)];
    _tradeHeaderView.backgroundColor = [UIColor whiteColor];
    self.tradeList.tableView.tableHeaderView = _tradeHeaderView;
    
    _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
    _headView.backgroundColor = kDefaultViewBackgroundColor;
    [_tradeHeaderView addSubview:_headView];

    _tradeAttstr = [[NSMutableAttributedString alloc] initWithString:@"我的交易\n" attributes:@{NSForegroundColorAttributeName:kDarkGrayColor}];
    NSAttributedString *tradStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"0"]  attributes:@{NSForegroundColorAttributeName:kLightBlackColor}];
    [_tradeAttstr appendAttributedString:tradStr];
    
    self.tradeBtn = [self creatBtnWithFrame:CGRectMake(0, 0, BtnWidth, 70) andImage:@"jiaoyi1" andTitle:@""];
    [self.tradeBtn setAttributedTitle:_tradeAttstr forState:UIControlStateNormal];
    self.tradeBtn.tag = 10;
    [_tradeHeaderView addSubview:_tradeBtn];

    self.releaseBtn = [self creatBtnWithFrame:CGRectMake(BtnWidth, 0, BtnWidth, 70) andImage:@"fabujiaoyi" andTitle:@"发布交易"];
    [self.releaseBtn setTitleColor:kLightBlackColor forState:UIControlStateNormal];
    self.releaseBtn.tag = 20;
    [_tradeHeaderView addSubview:_releaseBtn];
    
    UIView *horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(BtnWidth, 0, 0.6, 70)];
    horizonLineView.backgroundColor = kNormalGray;
    [_tradeHeaderView addSubview:horizonLineView];
    
    UIView *straightLineView =[[UIView alloc] initWithFrame:CGRectMake(0, 69.4, SCREEN_WIDTH, 0.6)];
    straightLineView.backgroundColor = kNormalGray;
    [_tradeHeaderView addSubview:straightLineView];
    
    _headBottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 70, SCREEN_WIDTH, 8)];
    _headBottomView.backgroundColor = kDefaultViewBackgroundColor;
    [_tradeHeaderView addSubview:_headBottomView];

    NSArray *titleArr = [NSArray arrayWithObjects:@"类型",@"状态", nil];
    self.imageMenu = [[HDImageMenuView alloc] initWithFrame:CGRectMake(0, 78, SCREEN_WIDTH, 40) titleArray:titleArr];
    self.imageMenu.delegate = (id)self;
    self.imageMenu.isHiddenBottomLine = NO;
    [_tradeHeaderView addSubview:self.imageMenu];
    
    //足迹tableViewHeader
    _footerHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
    _footerHeaderView.backgroundColor = [UIColor whiteColor];
    self.footprintList.tableView.tableHeaderView = _footerHeaderView;

    _footerAttstr = [[NSMutableAttributedString alloc] initWithString:@"我的足迹\n" attributes:@{NSForegroundColorAttributeName:kDarkGrayColor}];
    NSAttributedString *footerStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"0"]  attributes:@{NSForegroundColorAttributeName:kLightBlackColor}];
    [_footerAttstr appendAttributedString:footerStr];

    self.footerBtn = [self creatBtnWithFrame:CGRectMake(0, 0, BtnWidth, 70) andImage:@"foot" andTitle:@""];
    [self.footerBtn setAttributedTitle:_footerAttstr forState:UIControlStateNormal];
    self.footerBtn.tag = 30;
    [_footerHeaderView addSubview:_footerBtn];

    self.releaseFooterBtn = [self creatBtnWithFrame:CGRectMake(BtnWidth, 0, BtnWidth, 70) andImage:@"fabu" andTitle:@"发布足迹"];
    [self.releaseFooterBtn setTitleColor:kLightBlackColor forState:UIControlStateNormal];
    self.releaseFooterBtn.tag = 40;
    [_footerHeaderView addSubview:_releaseFooterBtn];
    
    UIView *horizonLineView1 =[[UIView alloc] initWithFrame:CGRectMake(BtnWidth, 0, 0.6, 70)];
    horizonLineView1.backgroundColor = kNormalGray;
    [_footerHeaderView addSubview:horizonLineView1];

    UIView *straightLineView1 =[[UIView alloc] initWithFrame:CGRectMake(0, 69.4, SCREEN_WIDTH, 0.6)];
    straightLineView1.backgroundColor = kNormalGray;
    [_footerHeaderView addSubview:straightLineView1];
}

//创建btn
- (GXButton*)creatBtnWithFrame:(CGRect)frame andImage:(NSString*)imageStr  andTitle:(NSString*)title{
    GXButton *btn = [GXButton buttonWithType:UIButtonTypeCustom];
    btn.relayout = YES;
    btn.frame = frame;
    btn.titleLabel.numberOfLines = 0;
    btn.imageViewFrame = CGRectMake((BtnWidth-90)/2, 15, 40, 40);
    btn.titleLabelFrame = CGRectMake((BtnWidth-90)/2+40, 0, 60, 70);
    [btn setBackgroundColor:[UIColor whiteColor]];
    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:kDarkGrayColor forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:13];
    [btn setImage:[UIImage imageNamed:imageStr] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(headBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//    [_headView addSubview:btn];
    return btn;
}

- (void)testDataFunc{
//    [self paddingSituationListData];
//    [self paddingContactsListData];
//    [self paddingTradeListData];
//    [self paddingFootprintListData];
    
    [netEngine requestProjectInfoWithTarget:self.VctrID hudView:self.contentView projectId:self.projectId];
    [netEngine requestProjectDynamicWithTarget:self.VctrID hudView:self.contentView projectId:self.projectId params:@{@"pageNo":@"1",@"pageSize":@"20"}];
    
    self.contactsList.pageNum = 1;
    self.tradeList.pageNum = 1;
    self.footprintList.pageNum = 1;
    [self requestProjectContactsHasHudView:YES];
    [self requestProjectTradeListHasHudView:YES];
    [self requestProjectFooterHasHudView:YES];
}

- (void)fillFilterData{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    
    //类型
    NSMutableArray *tempDataArray4 = [[NSMutableArray alloc] initWithCapacity:0];
    NSMutableArray *tempCodeArray4 = [[NSMutableArray alloc] initWithCapacity:0];
    NSString *projectInvestmentFile = [documentsPath stringByAppendingPathComponent:@"tradeTypeFile.plist"];
    if ([fileManager fileExistsAtPath:projectInvestmentFile]) {
        netEngine.tradeTypeArray = [[NSMutableArray alloc] initWithContentsOfFile:projectInvestmentFile];
    }
    for (NSDictionary *dict in netEngine.tradeTypeArray) {
        if ([dict isKindOfClass:[NSDictionary class]]) {
            [tempDataArray4 addObject:[HDUtil check:dict[@"name"]]];
            [tempCodeArray4 addObject:[HDUtil check:dict[@"code"]]];
        }
    }
    self.typeFilterVC.dataArray = tempDataArray4;
    self.typeFilterVC.codeArray = tempCodeArray4;
    
    //状态
    NSMutableArray *tempDataArray3 = [[NSMutableArray alloc] initWithCapacity:0];
    NSMutableArray *tempCodeArray3 = [[NSMutableArray alloc] initWithCapacity:0];
    NSString *projectStateFile = [documentsPath stringByAppendingPathComponent:@"tradeStateFile.plist"];
    if ([fileManager fileExistsAtPath:projectStateFile]) {
        netEngine.tradeStateArray = [[NSMutableArray alloc] initWithContentsOfFile:projectStateFile];
    }
    for (NSDictionary *dict in netEngine.tradeStateArray) {
        if ([dict isKindOfClass:[NSDictionary class]]) {
            [tempDataArray3 addObject:[HDUtil check:dict[@"name"]]];
            [tempCodeArray3 addObject:[HDUtil check:dict[@"code"]]];
        }
    }
    self.stateFilterVC.dataArray = tempDataArray3;
    self.stateFilterVC.codeArray = tempCodeArray3;
    self.typeFilterVC.stateArray = [self creatStateArrayWithArray:self.typeFilterVC.dataArray];
    self.stateFilterVC.stateArray = [self creatStateArrayWithArray:self.stateFilterVC.dataArray];
    
    self.stateVCArray = [NSMutableArray arrayWithObjects:self.typeFilterVC.stateArray,self.stateFilterVC.stateArray, nil];
}

- (NSMutableArray *)creatStateArrayWithArray:(NSArray*)array{
    NSMutableArray *mutalArray = [[NSMutableArray alloc] initWithCapacity:0];
    for (int i= 0; i<array.count; i++) {
        [mutalArray addObject:@"NO"];
    }
    return mutalArray;
}

- (void)paddingSituationListData{
    MSProjectModel *model = [[MSProjectModel alloc] init];
    model.title = @"上海浦东世和空港中心商业住房项目";
    model.projectType =  @"房地产";
    model.projectState =  @"主体施工";
    model.projectArea =  @"上海";
    model.projectPeriod =  @"2016.10.08-2018.06.08";
    model.investment =  @"2亿";
    model.address =  @"上海市经济技术开发区江华路2号";
    model.time =  @"2016.10.08";
    model.introduction =  @"项目为四栋单独塔楼，一座宾馆，一做酒店式办公楼，地下部分主题为一个小楼盘，一做酒店式办公楼，整个项目投资回报率非常高,整个项目投资回报率非常高";
    
    MSProjectDynamicModel *dynamicodel = [[MSProjectDynamicModel alloc] init];
    dynamicodel.title = @"项目动态更新了";
    dynamicodel.time =  @"12：00";
    dynamicodel.brief =  @"机电标已经发标书，共分两个包，投标截止日期，8月8日-11月26日";
    dynamicodel.type =  @"[匿名会员]";
    dynamicodel.memberLevel =  @"2";
    
    MSProjectDynamicModel *dynamicodel2 = [[MSProjectDynamicModel alloc] init];
    dynamicodel2.title = @"上海浦东世和空港中心商业住房项目";
    dynamicodel2.time =  @"12：00";
    dynamicodel2.brief =  @"主体施工";
    dynamicodel2.type =  @"[系统录入]";
    dynamicodel2.memberLevel =  @"上海";
    
    model.projectDynamic =  @[dynamicodel,dynamicodel2,dynamicodel];
    
    self.situationList.isClick = NO;
    self.situationList.model = model;
}

- (void)paddingContactsListData{
    MSDetailContactModel *model = [[MSDetailContactModel alloc] init];
    model.name = @"周长生";
    model.position = @"项目经理";
    model.company = @"上海电力有限公司";
    model.telephone = @"187****6786";
    model.address = @"上海市宝山区友谊路89号";
    model.source = @"平台采集";
    model.time = @"08.13";
    model.otherProject = @"3";
    
//    self.contactsList.contactArray = @[@[model,model,model],@[model,model,model]];
}

- (void)paddingTradeListData{
    MSTradeModel *model = [[MSTradeModel alloc] init];
    model.title = @"上海浦东世和空港中心商业住房项目";
    model.projectType = @"求购业主联系人信息";
    model.tradeState = @"交易中";
    model.tradeNum = @"3次交易";
    model.name = @"周世鹏";
    model.position = @"经理";
    model.theme = @"电缆附件招标最新进展";
    model.content = @"杭州地铁二号线目前极影施工阶段";
    model.tradeEvaluate = @"评价              ";
    model.tradePrice = @"12";
    model.memberType = @"[匿名会员]";
    model.memberLevel = @"2钻会员";
    model.time = @"2016.9.15";
    
    MSTradeModel *model1 = [[MSTradeModel alloc] init];
    model1.title = @"上海浦东世和空港中心商业住房项目";
    model1.projectType = @"出售进展信息";
    model1.tradeState = @"已过期";
    model1.tradeNum = @"5次交易";
    model1.name = @"王鹏辉";
    model1.position = @"主管";
    //    model1.theme = @"电缆附件招标最新进展";
    //    model1.content = @"杭州地铁二号线目前极影施工阶段";
    //    model1.tradeEvaluate = @"评价              ";
    model1.tradePrice = @"23";
    model1.memberType = @"[系统录入]";
    model1.memberLevel = @"3";
    model1.time = @"2016.9.15";
    
    MSTradeModel *model2 = [[MSTradeModel alloc] init];
    model2.title = @"上海浦东世和空港中心商业住房项目";
    model2.projectType = @"求购设计师项目联系人信息";
    model2.tradeState = @"公开显示";
    model2.tradeNum = @"23次交易";
    //    model2.name = @"李光成";
    model2.position = @"总监";
    model2.theme = @"电缆附件招标最新进展";
    model2.content = @"杭州地铁二号线目前极影施工阶段";
    model2.tradeEvaluate = @"评价              ";
    model2.tradePrice = @"45";
    model2.memberType = @"[匿名会员]";
    model2.memberLevel = @"1";
    model2.time = @"2016.9.15";
    
    self.tradeList.dataArray = [@[model,model1,model2,model1,model,model1,model2] mutableCopy];
}

- (void)paddingFootprintListData{
    MSFootprintModel *model = [[MSFootprintModel alloc] init];
    model.name = @"张三";
    model.memberLevel = @"2";
    model.time = @"2016.9.15";
    model.introduction = @"杭州地铁二号线目前极影施工阶段杭州地铁二号线目前极影施工阶段";
    model.goodNum = @"25";
    model.badNum = @"13";
    model.isSelf = NO;
    model.isGoodEd = NO;
    model.isBadEd = NO;
    
    NSArray *imagearray = @[@"example.jpg",
                            @"5.jpg",
                            @"6.jpg",
                            @"7.jpg",
                            @"6.jpg"];
    NSMutableArray* bannerArray = [[NSMutableArray alloc] initWithCapacity:0];
    for (int i =0; i<imagearray.count; i++) {
        propertyPicture* item = [[propertyPicture alloc] init];
        item.path = imagearray[i];
        [bannerArray addObject:item];
    }
    model.imageArray = bannerArray;
    
    MSFootprintModel *model2 = [[MSFootprintModel alloc] init];
    model2.name = @"王峰";
    model2.memberLevel = @"2";
    model2.time = @"2016.9.15";
    model2.introduction = @"上海浦东世和空港中心商业住房项目";
    model2.goodNum = @"5";
    model2.badNum = @"3";
    model2.isSelf = NO;
    model2.isGoodEd = NO;
    model2.isBadEd = NO;
    
    NSMutableArray* bannerArray2 = [[NSMutableArray alloc] initWithCapacity:0];
    model2.imageArray = bannerArray2;
    
    MSFootprintModel *model3 = [[MSFootprintModel alloc] init];
    model3.name = @"王峰";
    model3.memberLevel = @"2";
    model3.time = @"2016.9.15";
    model3.introduction = @"上海浦东世和空港中心商业住房项目";
    model3.goodNum = @"5";
    model3.badNum = @"3";
    model3.isSelf = NO;
    model3.isGoodEd = NO;
    model3.isBadEd = NO;
    model3.imageArray = bannerArray2;
    
    MSFootprintModel *model4 = [[MSFootprintModel alloc] init];
    model4.name = @"王峰";
    model4.memberLevel = @"2";
    model4.time = @"2016.9.15";
    model4.introduction = @"上海浦东世和空港中心商业住房项目";
    model4.goodNum = @"5";
    model4.badNum = @"3";
    model4.isSelf = NO;
    model4.isGoodEd = NO;
    model4.isBadEd = NO;
    model4.imageArray = bannerArray;
    
    self.footprintList.dataArray = [@[model,model2,model4,model3] mutableCopy];
}

- (void)updateViewController:(NSNotification *)note {
    NSDictionary *responseDic = note.userInfo;
    if (responseDic[Receiver]==self.VctrID) {
        if (responseDic[@"TrackProject"]!=nil){
            GXButton *btn = [_sideView viewWithTag:10];
            if ([btn.titleLabel.text isEqualToString:@"跟踪"]) {
                [btn setTitle:@"取消跟踪" forState:UIControlStateNormal];
                [HDUtil showMessage:@"已跟踪"];
            }
            else{
                if ([btn.titleLabel.text isEqualToString:@"取消跟踪"]) {
                    [btn setTitle:@"跟踪" forState:UIControlStateNormal];
                    [HDUtil showMessage:@"已取消跟踪"];
                }
            }
        }
        if (responseDic[@"AttentionProject"]!=nil){
            GXButton *btn = [_sideView viewWithTag:11];
            if ([btn.titleLabel.text isEqualToString:@"关注"]) {
                [btn setTitle:@"取消关注" forState:UIControlStateNormal];
                [HDUtil showMessage:@"已关注"];
            }
            else{
                if ([btn.titleLabel.text isEqualToString:@"取消关注"]) {
                    [btn setTitle:@"关注" forState:UIControlStateNormal];
                    [HDUtil showMessage:@"已取消关注"];
                }
            }
        }
        if (responseDic[@"ProjectInfo"]!=nil){
            self.situationList.isClick = NO;
            MSProjectModel *model = responseDic[@"ProjectInfo"];
            self.projectModel = model;
            
            self.situationList.model = model;
            [self.situationList.tableView reloadData];
            
            NSString *trackStr = model.isTrack?@"取消跟踪":@"跟踪";
            GXButton *sideButton = [_sideView viewWithTag:10];
            [sideButton setTitle:trackStr forState:UIControlStateNormal];
            
            NSString *attentionStr = model.isAttention?@"取消关注":@"关注";
            GXButton *sideButton1 = [_sideView viewWithTag:11];
            [sideButton1 setTitle:attentionStr forState:UIControlStateNormal];
        }
        if (responseDic[@"ProjectDynamic"]!=nil){
            if (responseDic[@"state"]!=nil){
                self.situationList.isClick = NO;
//                if (!self.projectModel) {
//                    self.projectModel = [[MSProjectModel alloc] init];
//                }
                NSArray *tempArray = responseDic[@"ProjectDynamic"];
                self.situationList.projectDynamicArray = tempArray;
                [self.situationList.tableView reloadData];
            }
            else{
                self.situationList.dataArray = self.situationList.dataArray;
            }
        }
        if (responseDic[@"ProjectContacts"]!=nil){
            if (responseDic[@"state"]!=nil){
//                self.contactsList.totalPagesNum = [responseDic[@"totalPage"] intValue];
//                if (self.contactsList.pageNum == 1) {
//                    self.contactsList.dataArray = nil;
//                }
                NSMutableArray *dataArrray = responseDic[@"ProjectContacts"];
                self.contactsList.contactArray = dataArrray;
            }
//            else{
//                self.contactsList.dataArray = self.contactsList.dataArray;
//            }
        }
        if (responseDic[@"ProjectTradeList"]!=nil){
            if (responseDic[@"state"]!=nil){
                self.tradeList.totalPagesNum = [responseDic[@"totalPage"] intValue];
                if (self.tradeList.pageNum == 1) {
                    self.tradeList.dataArray = nil;
                }
                NSMutableArray *dataArrray = [[NSMutableArray alloc] initWithArray:self.tradeList.dataArray];
                [dataArrray addObjectsFromArray:responseDic[@"ProjectTradeList"]];
                self.tradeList.dataArray = dataArrray;
                
                _tradeAttstr = [[NSMutableAttributedString alloc] initWithString:@"我的交易\n" attributes:@{NSForegroundColorAttributeName:kDarkGrayColor}];
                NSAttributedString *tradStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld",dataArrray.count]  attributes:@{NSForegroundColorAttributeName:kLightBlackColor}];
                [_tradeAttstr appendAttributedString:tradStr];
                [self.tradeBtn setAttributedTitle:_tradeAttstr forState:UIControlStateNormal];
            }
            else{
                self.tradeList.dataArray = self.tradeList.dataArray;
            }
        }
        if (responseDic[@"MyFoot"]!=nil){
            if (responseDic[@"state"]!=nil){
                self.footprintList.totalPagesNum = [responseDic[@"totalPage"] intValue];
                if (self.footprintList.pageNum == 1) {
                    self.footprintList.dataArray = nil;
                }
                NSMutableArray *dataArrray = [[NSMutableArray alloc] initWithArray:self.footprintList.dataArray];
                [dataArrray addObjectsFromArray:responseDic[@"MyFoot"]];
                self.footprintList.dataArray = dataArrray;
                
                _footerAttstr = [[NSMutableAttributedString alloc] initWithString:@"我的足迹\n" attributes:@{NSForegroundColorAttributeName:kDarkGrayColor}];
                NSAttributedString *footerStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld",dataArrray.count]  attributes:@{NSForegroundColorAttributeName:kLightBlackColor}];
                [_footerAttstr appendAttributedString:footerStr];
                [self.footerBtn setAttributedTitle:_footerAttstr forState:UIControlStateNormal];
            }
            else{
                self.footprintList.dataArray = self.footprintList.dataArray;
            }
        }
        if (responseDic[@"DeleteFooter"]!=nil){
            [self.footprintList.dataArray removeObjectAtIndex:_footerIndex];
            NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_footerIndex inSection:0];
            [self.footprintList.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
//            [self performSelector:@selector(reloadFootprintListTableView) withObject:nil afterDelay:1];
        }
        if (responseDic[@"GoodFooter"]!=nil){
            MSFootprintModel *model = self.footprintList.dataArray[_footerIndex];
            model.isGoodEd = YES;
//            model.goodNum = [NSString stringWithFormat:@"%ld",[model.goodNum integerValue]+1];
            [self.footprintList.tableView reloadData];
        }
        if (responseDic[@"BadFooter"]!=nil){
            MSFootprintModel *model = self.footprintList.dataArray[_footerIndex];
            model.isBadEd = YES;
            model.badNum = [NSString stringWithFormat:@"%ld",[model.badNum integerValue]+1];
            [self.footprintList.tableView reloadData];
        }
    }
}

#pragma mark - DYTableViewProtocol
/** 上拉 */
- (void)pullTableView:(UITableView *)tableView isNextPage:(BOOL)isNextPage{
    if (self.menu.selectedIndex == 1) {
        self.contactsList.pageNum++;
        [self requestProjectContactsHasHudView:NO];
    }
    if (self.menu.selectedIndex == 2) {
        self.tradeList.pageNum++;
        [self requestProjectTradeListHasHudView:NO];
    }
    if (self.menu.selectedIndex == 3) {
        self.contactsList.pageNum++;
        [self requestProjectFooterHasHudView:NO];
    }
}

- (void)pullRefreshRequest{
    if (self.menu.selectedIndex == 1) {
        self.contactsList.pageNum = 1;
        [self requestProjectContactsHasHudView:NO];
    }
    if (self.menu.selectedIndex == 2) {
        self.contactsList.pageNum = 1;
        [self requestProjectTradeListHasHudView:NO];
    }
    if (self.menu.selectedIndex == 3) {
        self.contactsList.pageNum = 1;
        [self requestProjectFooterHasHudView:NO];
    }
}

- (void)requestProjectContactsHasHudView:(BOOL)hasHudView{
    UIView * hudView = hasHudView?self.contactsList.view:nil;
    NSString *pageNumber = [NSString stringWithFormat:@"%d",self.contactsList.pageNum];
    NSDictionary *dict = @{
                           @"pageNo":pageNumber,
                           @"pageSize":@"100",
                           };
    [netEngine requestProjectContactsWithTarget:self.VctrID hudView:hudView projectId:self.projectId params:dict];
}

- (void)requestProjectTradeListHasHudView:(BOOL)hasHudView{
    UIView * hudView = hasHudView?self.tradeList.view:nil;
    NSString *pageNumber = [NSString stringWithFormat:@"%d",self.tradeList.pageNum];
    NSDictionary *dict = @{
                           @"pageNo":pageNumber,
                           @"pageSize":@"10",
                           @"status":currentStateStr,
                           @"type":currentTypeStr};
    [netEngine requestProjectTradeListWithTarget:self.VctrID hudView:hudView projectId:self.projectId params:dict];
}

- (void)requestProjectFooterHasHudView:(BOOL)hasHudView{
    UIView * hudView = hasHudView?self.footprintList.view:nil;
    NSString *pageNumber = [NSString stringWithFormat:@"%d",self.footprintList.pageNum];
    NSDictionary *dict = @{
                           @"pageNo":pageNumber,
                           @"pageSize":@"10",
                           };
    [netEngine requestProjectFooterWithTarget:self.VctrID hudView:hudView projectId:self.projectId params:dict];
}

#pragma mark - HDMenuViewDelegate
- (void)selectMenuIndex:(int)index{
    _scrollView.contentOffset = CGPointMake(SCREEN_WIDTH*index, 0);

    if ([self.filterVC.view superview]) {
        [self.filterVC dismiss];
    }
    [self.imageMenu setBtnStateWithIndex:_lastIndex state:NO];
    _sideView.hidden = YES;
    rightBarBtn.selected = NO;
}

#pragma mark - HDMenuImageDelegate
- (void)selectImageMenuIndex:(int)index{
    if (_lastIndex != -1) {
        if (index == _lastIndex) {
            self.filterVC = self.filterVCArray[index];
            if ([self.filterVC.view superview]) {
                [self.filterVC dismiss];
                [self.imageMenu setBtnStateWithIndex:_lastIndex state:NO];
            }
            else{
                [self.filterVC showInView:_positionY];
                [self.imageMenu setBtnStateWithIndex:index state:YES];
            }
        }
        else{
            self.filterVC = self.filterVCArray[_lastIndex];
            if ([self.filterVC.view superview]) {
                [self.filterVC dismiss];
                [self.imageMenu setBtnStateWithIndex:_lastIndex state:NO];
            }
            
            self.filterVC = self.filterVCArray[index];
            if ([self.filterVC.view superview]) {
                [self.filterVC dismiss];
            }
            else{
                [self.filterVC showInView:_positionY];
                [self.imageMenu setBtnStateWithIndex:index state:YES];
            }
        }
    }
    else{//第一次点击
        self.filterVC = self.filterVCArray[index];
        
        if ([self.filterVC.view superview]) {
            [self.filterVC dismiss];
        }
        else{
            [self.filterVC showInView:_positionY];
            [self.imageMenu setBtnStateWithIndex:index state:YES];
        }
    }
    _lastIndex = index;
}

#pragma mark - MSSaleFilterDelegate
- (void)selectedFilterWithParmas:(NSInteger)index code:(NSString*)codeValue{//筛选
    [self.imageMenu setBtnStateWithIndex:_lastIndex state:NO];
    NSArray *stateArray = self.stateVCArray[_lastIndex];
    if ([stateArray containsObject:@"YES"]) {
        [self.imageMenu setBtnTitleColorWithIndex:_lastIndex state:YES];
    }
    else{
        [self.imageMenu setBtnTitleColorWithIndex:_lastIndex state:NO];
    }
    
    if (_lastIndex == 1) {//行业
        if ([stateArray containsObject:@"YES"]) {
            currentTypeStr = codeValue;
        }
        else{
            currentTypeStr = @"";
        }
    }
    if (_lastIndex == 2) {//阶段
        if ([stateArray containsObject:@"YES"]) {
            currentStateStr = codeValue;
        }
        else{
            currentStateStr = @"";
        }
    }
    if (index != 1000) {
        self.tradeList.pageNum = 1;
        [self requestProjectTradeListHasHudView:YES];
    }
}

- (void)headBtnClick:(GXButton *)btn{
//    if (self.currentVC==self.shopListVCArray[2]) {//第三个表
        if (btn.tag == 10) {
            MSMytradeViewController *vc = [[MSMytradeViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (btn.tag == 20) {//发布交易
            __weak MSProjectDetailViewController *weakSelf = self;
            MSReleaseTradeViewController *vc = [[MSReleaseTradeViewController alloc] init];
            vc.model = self.projectModel;
            vc.choickBlock = ^(){
                [weakSelf requestProjectTradeListHasHudView:YES];
            };
            [rootNavigation pushViewController:vc animated:YES];
        }
//    }
//    if (self.currentVC==self.shopListVCArray[3]) {//第四个表
        if (btn.tag == 30) {
            MSMyFootprintViewController *vc = [[MSMyFootprintViewController alloc] init];
            [rootNavigation pushViewController:vc animated:YES];
        }
        if (btn.tag == 40) {//发布足迹
            __weak MSProjectDetailViewController *weakSelf = self;
            MSReleaseFooterViewController *vc = [[MSReleaseFooterViewController alloc] init];
            vc.choickBlock = ^(){
                [weakSelf requestProjectFooterHasHudView:YES];
            };
            vc.projectId = _projectId;
            [rootNavigation pushViewController:vc animated:YES];
        }
//    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.menu.selectedIndex==2) {//第三个表
        MyTradeConfirmViewController *vc = [[MyTradeConfirmViewController alloc] init];
        vc.tradeType = TradeType_Sale;
        [rootNavigation pushViewController:vc animated:YES];
    }
}

#pragma mark - 项目信息更多按钮点击
- (void)clickMoreBtnIsFold:(BOOL)isFold{
    self.situationList.isClick = isFold;
    [self.situationList.tableView reloadData];
}

#pragma mark - 联系人列表点击
- (void)ContactSClick:(ContactSClickType)type andModel:(MSDetailContactModel*)model{
    if (type == ContactSClickType_Guide) {
        MSRecommenDetailVC *vc = [[MSRecommenDetailVC alloc] init];
        model.projectName = self.situationList.model.title;
        vc.model = model;
        [rootNavigation pushViewController:vc animated:YES];
    }
    if (type == ContactSClickType_Look) {
        MSMyFollowViewController *vc = [[MSMyFollowViewController alloc] init];
        vc.projectType = MSProjectType_Other;
        vc.peopleId = model.peopleId;
        [rootNavigation pushViewController:vc animated:YES];
    }
    if (type == ContactSClickType_Correct) {
        MSContactsCorrectViewController *vc = [[MSContactsCorrectViewController alloc] init];
        vc.peopleId = model.peopleId;
        [rootNavigation pushViewController:vc animated:YES];
    }
    if (type == ContactSClickType_Saling){
        MSSaleContactsOfPeopleVC *vc = [[MSSaleContactsOfPeopleVC alloc] init];
        vc.peopleId = model.telephone;
        [rootNavigation pushViewController:vc animated:YES];
    }
}

#pragma mark - 足迹列表点击
- (void)footprintClick:(FootprintClickType)type clickCellIndex:(NSInteger)index{
    _footerIndex = index;
    
    MSFootprintModel *model = self.footprintList.dataArray[index];
    NSString *footerId = model.itemID;

    if (type == FootprintClickType_Image){
        NSMutableArray *commentImageArr = [[NSMutableArray alloc] init];
        for (int i = 0; i < model.imageArray.count; i++) {
            propertyPicture *pictureModel = (propertyPicture *)model.imageArray[i];
            [commentImageArr addObject:pictureModel.path];
        }
        
        MSPictureShowViewController *pictureShowVC = [[MSPictureShowViewController alloc] init];
        pictureShowVC.titleStr = @"";
        pictureShowVC.imageArr = commentImageArr;
        pictureShowVC.imageIndex = 0;
        [rootNavigation pushViewController:pictureShowVC animated:YES];
        return;
    }

    if (type == FootprintClickType_Delete) {
        NSString *remindLabelStr = @"是否确认删除该条足迹";
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:remindLabelStr message:nil delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"确认", nil];
        alertView.tag = index;
        [alertView show];
    }
    if (type == FootprintClickType_Good) {
        [netEngine requestGoodFooterWithTarget:self.VctrID hudView:self.contentView footerId:footerId];
    }
    if (type == FootprintClickType_Bad) {
        [netEngine requestBadFooterWithTarget:self.VctrID hudView:self.contentView footerId:footerId];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        MSFootprintModel *model = self.footprintList.dataArray[_footerIndex];
        NSString *footerId = model.itemID;
        
        [netEngine requestDeleteFooterWithTarget:self.VctrID hudView:self.contentView footerId:footerId];
    }
}

- (void)reloadFootprintListTableView{
    [self.footprintList.tableView reloadData];
}

- (MSSaleFilterViewController *)creatFilterVC
{
    MSSaleFilterViewController *VC = [[MSSaleFilterViewController alloc] init];
    VC.delegate = (id<MSSaleFilterDelegate>)self;
    return VC;
}

- (void)tapClick{
    _sideView.hidden = YES;
    rightBarBtn.selected = NO;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if ([self.filterVC.view superview]) {
        [self.filterVC dismiss];
    }
    [self.imageMenu setBtnStateWithIndex:_lastIndex state:NO];
    _sideView.hidden = YES;
    rightBarBtn.selected = NO;
}

@end
